
Character = function (entity)
{
	/********************************************/
	/*				Properties					*/
	/********************************************/
	
		this.m_Lerp;
		this.m_Sprite;	/*!< Sprite attached to the current character			*/
		this.m_Entity;	/*!< Entity on wich the current character is attached	*/
	
	/********************************************/
	/*				Constructor					*/
	/********************************************/
	
	this.m_Entity	=	entity;
	
	this.m_Sprite = new Sprite(g_Image, 9, 8, 1, 80, entity);
	this.m_Lerp= new Lerp();
	
	Mouse.MouseDownHandlers.push(new Method(this, this.MoveCharacter));
}

Character.prototype.Update	=	function()
{
	this.m_Sprite.Update();
	
	if(this.m_Lerp.m_End==false)
	{
		this.m_Entity.m_Transform.SetPositionv(this.m_Lerp.Update());
	}
	
}
Character.prototype.MoveCharacter = function(x, y)
{
	
	if(Mouse.Buttons[2]==MouseState.Down)
	{
	// temp fix
	x= x-250;
	y = -y+250;

	var rightVec = new Vec4(1.0, 0.0, 0.0, 1.0);
	
	console.log("x" +x);
	console.log("y" +y);
	
	var positionClick = new Vec4(x, y, 0.0, 1.0);

	
	this.m_Lerp.StartVelocity(0.16, this.m_Entity.m_Transform.m_Position, positionClick );
	
	var vecPosition = this.m_Entity.m_Transform.m_Position;
	var vec = positionClick.Minus(vecPosition);

	var div = (vec.Length()+rightVec.Length());
	var angle=Math.acos( (Vec4.Dot(rightVec, vec))/div );
	
	if(vec.y>0)
	{
		angle = -angle;
	}
	
	if((angle> -Math.PI/8) && (angle< Math.PI/8))
	{
		console.log(6);
		this.m_Sprite.m_CurrentAnimation=1;
	}
	else if((angle> Math.PI/8) && (angle< 3*Math.PI/8))
	{
		this.m_Sprite.m_CurrentAnimation=2;
		console.log(9);
	}
	else if((angle> 3*Math.PI/8) && (angle< 5*Math.PI/8))
	{
		this.m_Sprite.m_CurrentAnimation=3;
		console.log(8);
	}
	else if((angle> 5*Math.PI/8) && (angle< 7*Math.PI/8))
	{
		this.m_Sprite.m_CurrentAnimation=4;
		console.log(7);
	}
	else if((angle> 7*Math.PI/8) || (angle< -7*Math.PI/8))
	{
		this.m_Sprite.m_CurrentAnimation=5;
		console.log(4);
	}
	else if((angle> -7 *Math.PI/8) && (angle< -5*Math.PI/8))
	{
		console.log(1);
		this.m_Sprite.m_CurrentAnimation=6;
	}
	else if((angle> -5 *Math.PI/8) && (angle< -3*Math.PI/8))
	{	
		console.log(2);
		this.m_Sprite.m_CurrentAnimation=7;
	}
	else if((angle> -3 *Math.PI/8) && (angle< -1*Math.PI/8))
	{	
		console.log(3);
		this.m_Sprite.m_CurrentAnimation=0;
	}
	}
}
